/*
 *  $Id: HolyTree.cs 1067 2010-05-21 11:00:43Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Earth.Lands {
    public class HolyTree: LandCard {
        public HolyTree(): base("001_e_l_holy_tree") {
            Level = CompleteLevel.ReadyForTest;
            Version = 1;
            Element = ElementType.Earth;
            Value = 100;
            AddManaCost(ElementType.Earth, 3);
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add(new Affects.ManaIncome(ElementType.Earth, 2));
            affects.Add<HolyTreeAura>();
        }

        private class HolyTreeAura: CreatureAuraAffect {
            public HolyTreeAura(): base(true, false) {}

            public override string Id {
                get { return AffectManager.GetCardId<HolyTree>("aura"); }
            }

            protected override Affect CreateSubAffect() {
                return new HolyTreeAffect();
            }
        }

        private class HolyTreeAffect: SpellAffect<HolyTree> {
            public HolyTreeAffect() {
                Add(new Affects.ModMaxHealth(2));
                Add(new Affects.Guardian());
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnAfterDamage += DoDamage;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnAfterDamage -= DoDamage;
            }

            private void DoDamage(AbstractObject target, DamageInfo damage) {
                if (target == Owner && target.Owner.State == PlayerState.Defence && damage.RealDamage > 0) {
                    target.AddAffect(new TimeAffect(3, new Affects.AntiFlag<Affects.Guardian>()));
                }
            }
        }
    }
}
